package problemloesen.projekt01.testcases;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import problemloesen.projekt01.PointApprox;

/**
 * Test-Class for poly function in PointApprox
 */
public class TestPoly {


	@Test
	public void test00() {
		// test a0 for x = 0 to 10 with step size 0.1
		// for different a values for -5 to 5 step size 0.1
		for (double a0 = -5.0; a0 <= 5; a0 += 0.1) {
			for (double x = 0; x <= 10; x += 0.1) {
				double a[] = { a0 };
				assertEquals(a0, PointApprox.poly(x, a), 0.1);
			}
		}
	}

	@Test
	public void test01() {
		// test a0,a1 for x = 0 to 10 with step size 0.1
		// for different a values for -5 to 5 step size 0.1
		for (double a0 = -5.0; a0 <= 5; a0 += 0.1) {
			for (double a1 = -5.0; a0 <= 5; a0 += 0.1) {
				for (double x = 0; x <= 10; x += 0.1) {
					double a[] = { a0, a1 };
					assertEquals((x * a1 + a0), PointApprox.poly(x, a), 0.1);
				}
			}
		}
	}
	
	@Test
	public void test02() {

		double a[] = 	{ 
							-5.0, // a0
							-5.0, // a1
							-5.0, // a2
							-5.0, // a3
							-5.0, // a4 
							-5.0  // a5
						};
		// for all i in a 
		for (int i = 0; i < a.length ; i++) {
			// for a[i] form start to 5.0 
			for (; a[i] <= 5; a[i] += 0.1) {
				// for x form 0 to 10
				for (double x = 0; x <= 10; x += 0.1) {
					double compare = 0.0;
					// clac compare 
					for (int j = 0; j < a.length; j++)
					{
						compare += (a[j] * Math.pow(x, j));
					}
					assertEquals(compare, PointApprox.poly(x, a), 0.01);
				}
			}
		}
	}

}
